package cn.hg.jfsa.manage.controller.system;

import cn.hg.base.jfinal.controller.BaseController;
import cn.hg.base.kit.StrExtKit;
import cn.hg.jfsa.common.LogManager;
import cn.hg.jfsa.manage.web.LayuiPage;
import cn.hg.jfsa.model.JfsaLogAction;
import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.SqlPara;

public class JfsaActionLogController extends BaseController {
	/**
	 * 跳转到列表页面
	 */
	public void index() {
	}

	public void ajaxSearch() {
		// 查询之前强制日志管理器将缓存写入数据库
		LogManager.me().flush();

		// 建立查询键值对
		Kv para = Kv.by("adminName", this.get("adminName"))
				.set("actionName", this.get("actionName"))
				.set("uri", this.get("uri"))
				.set("sortField", StrExtKit.humpToUnderline(this.get("sortField")))
				.set("sortType", this.get("sortType", "ASC"));

		// 通过SQL模板引擎构建SQL及参数
		SqlPara sqlPara = Db.getSqlPara("system.findActionLog", para);

		// 执行查询
		Page<JfsaLogAction> page = JfsaLogAction.DAO.paginate(getParaToInt("page"), getParaToInt("limit"), sqlPara);

		// 返回Ajax调用的Json结果
		this.renderJson(new LayuiPage(page));
	}

	public void view() {
		this.setAttr("logAction", JfsaLogAction.DAO.findById(this.getParaToInt("id")));
	}

}
